WRITE(2)
## NAME
write - write data to a file descriptor
## SYNOPSIS
*#include <unistd.h>*

*ssize\_t write*(*int* fd, *const void* \*buf, *size\_t* count);
## DESCRIPTION
The *write*() call writes up to the specified *count* of bytes from the buffer
*buf* to the object referenced by file descriptor *fd*.

On files that support seeking the write begins at the current file offset and
the file offset is incremented by the number of bytes writren. A write will extend
the file. If the *O\_APPEND* flag was specified for this file then the file
offset is set to the end of the file before the write occurs, and it and the
write occur as one atomic operation.

If the count is zero then zero will be returned. If the count is larger than
*SSIZE\_MAX* an error will be returned.

A write from a device such as a *socket*(4), *tty*(4) or *fifo*(7) may block and
wait for space to write data. This behaviour is controlled by the *O\_NDELAY*
flag when opening the file. Waiting *write* calls may also be interrupted by a
*signal*(7).
## RETURN VALUE
On success, the number of bytes successfully written is returned.
If no data could be written due to an error then -1 is returned and errno is set.
## ERRORS
:*EAGAIN*
  The write would block but the *O\_NDELAY* flag is set on the file descriptor.
:*EBADF*
  The file descriptor *fd* is not open for writing.
:*EFAULT*
  The address passed for the path is invalid.
:*EINTR*
  The write was interrupted by a *signal*(7) before any data was read.
:*EINVAL*
  The file descriptor refers to an object which does not support this operation
  or the count specified exceeds *SSIZE\_MAX*.
:*EIO*
  An I/O error occurred.
:*ENOSPC*
  No space was available to write the new data.
:*EPIPE*
  A write to a pipe or socket was attempted when there is no reader. The writing
  process will also receive a *SIGPIPE* signal.
## CONFORMING TO
V7, UZI, POSIX.1-2001.
## NOTES
The behaviour of a *write*(2) when passed a count larger than *SSIZE\_MAX* is
undefined by the standards. Fuzix returns *EINVAL* to provide a clear defined
behaviour because on an 8 or 16bit machine it is relatively easy to accidentally
hit this limit.
## SEE ALSO
*lseek*(2), *open*(2), *write*(2), *socket*(4), *tty*(4), *signal*(7)
